<?php
global $_W, $_GPC;
load()->func('tpl');
$html_title = $_W['current_module']['title'];
$op = !empty($_GPC['op']) ? $_GPC['op'] : '';
$extra = !empty($_GPC['extra']) ? $_GPC['extra'] : '';
$isactive = 'index';//底部菜单切换效果
//页面显示条数
$pagesize = 20;
$page = max(1, $_GPC['page']);
$start = ($page - 1) * $pagesize;

//首页展示
if ($op == 'index') {
    if ($extra == 'list') {
        $user_id = checkMobileLogin() ? session('user_id') : 0;
        $time = time();
        $field = "A.id,A.title,A.remark,A.thumb,A.begin_time,A.task_money,A.release_num,A.receive_num ";
        $where = "A.id>0 and A.delete_time=0 and A.end_time>'" . ($time + 2) . "' ";
        $order = "A.id desc ";
        $limit = "$start,$pagesize";
        $sql = "select $field from ims_yq_haircircle_task A where $where order by $order limit $limit";
        $list = pdo_fetchall($sql);
        if (empty($list)) {
            $list = array();
            ajaxSuccess('success', $list);
        }
        foreach ($list as $k => $v) {
            $list[$k]['jumpurl'] = $this->createMobileUrl('task', array('op' => 'detail', 'id' => $v['id']));
            $list[$k]['thumb'] = cmf_get_upload_url($v['thumb']);
            $list[$k]['remark'] = cutstr_html(htmlspecialchars_decode($v['remark']));
            if(time()<$v['begin_time']){
                $list[$k]['task_status'] = '任务未开始';
            }else{
                $list[$k]['task_status'] = '任务进行中';
            }
            if (empty($user_id)) {
                $list[$k]['task_status'] = '任务未开始';
            } else {
                $result = pdo_get('yq_haircircle_task_receive', array('taskid' => $v['id'], 'user_id' => $user_id), array('receive_status'));
                if (empty($result)) {
                    $list[$k]['user_task_status'] = '抢任务';
                } else {
                    switch ($result['receive_status']) {
                        case 0:
                            $list[$k]['user_task_status'] = '进行中';
                            break;
                        case 1:
                            $list[$k]['user_task_status'] = '已失效';
                            break;
                        case 2:
                            $list[$k]['user_task_status'] = '待审核';
                            break;
                        case 3:
                            $list[$k]['user_task_status'] = '已完结';
                            break;
                    }
                }
            }
        }
        ajaxSuccess('success', $list);
    }

    $res = "select title from ims_yq_haircircle_notice where delete_time=0 and status=1 order by id desc,status limit 4";
    $noteres = pdo_fetchall($res);
    if (empty($noteres)) {
        $noteres = [];
    }

    //获取轮播图
    $slider_sql = "select imgurl from " . tablename('yq_haircircle_home_slider') . " where delete_time=0 and isopen=1 order by 
     id desc limit 4";
    $slider = pdo_fetchall($slider_sql);
    if (!empty($slider)) {
        foreach ($slider as $item) {
            $sliderarr[] = cmf_get_upload_url($item['imgurl']);
        }
    } else {
        $sliderarr = [
            'http://ppoutbmy2.bkt.clouddn.com/timg%20%284%29.jpeg',
            'http://ppoutbmy2.bkt.clouddn.com/timg%20%288%29.jpeg',
            'http://ppoutbmy2.bkt.clouddn.com/timg%20%289%29.jpeg',
            'http://ppoutbmy2.bkt.clouddn.com/timg%20%282%29.jpeg',
        ];
    }
    include $this->template('index_index');
    exit;
}


//关于我们
if ($op == 'page' && $extra == 'about_us') {
    $setting = cmf_get_option('introduce_setting');
    $html_title = '关于我们';
    $content = isset($setting['about_us']) ? htmlspecialchars_decode($setting['about_us']) : '请在后台配置';
    include $this->template('index_page');
    exit;
}
//项目介绍
if ($op == 'page' && $extra == 'project_introduce') {
    $setting = cmf_get_option('introduce_setting');
    $html_title = '项目介绍';
    $content = isset($setting['project_introduce']) ? htmlspecialchars_decode($setting['project_introduce']) : '请在后台配置';
    include $this->template('index_page');
    exit;
}
//新人引导
if ($op == 'page' && $extra == 'new_introduce') {
    $html_title = '新人引导';
    $setting = cmf_get_option('introduce_setting');
    $content = isset($setting['new_introduce']) ? htmlspecialchars_decode($setting['new_introduce']) : '请在后台配置';
    include $this->template('index_page');
    exit;
}
//合作招商
if ($op == 'page' && $extra == 'cooperate') {
    $html_title = '合作招商';
    $setting = cmf_get_option('introduce_setting');
    $content = isset($setting['cooperate']) ? htmlspecialchars_decode($setting['cooperate']) : '请在后台配置';
    include $this->template('index_page');
    exit;
}
